﻿using System.IO;
using System.Xml.Serialization;
using FileDuplicateRemover.Core;

namespace FileDuplicateRemover.Gui
{
    public class FileEntityRepository : EntityRepository
    {
        public DuplicateListViewModel CreateViewModel()
        {
            return new DuplicateListViewModel();
        }

        public void SaveViewModel(string fullFileName, DuplicateListViewModel model)
        {
            using (TextWriter tw = new StreamWriter(fullFileName))
            {
                XmlSerializer xs = new XmlSerializer(typeof(DuplicateListViewModel));
                xs.Serialize(tw, model);
            }
        }

        public DuplicateListViewModel LoadViewModel(string fullFileName)
        {
            using (TextReader tr = new StreamReader(fullFileName))
            {
                XmlSerializer xs = new XmlSerializer(typeof(DuplicateListViewModel));
                DuplicateListViewModel res = (DuplicateListViewModel)xs.Deserialize(tr);

                return res;
            }
        }
    }
}
